﻿using UnityEngine;
using Yoozoo.Libs;

namespace WorldMapBase.Display
{
    public class MeshReplaceElement : IClass, IDisplayElement
    {        
        Transform m_RefTrans;

        private Vector3 m_position;

        private Vector3 m_scale;

        private Vector3 m_rotation;
        
        public Transform GetRefTrans
        {
            get
            {
                return m_RefTrans;
            }
        }
        
        public void OnReset()
        {
            if (null != m_RefTrans)
            {
                m_RefTrans = null;
            }
        }
        
        public int GetResID()
        {
            return 0;
        }
        
        public void OnCreate(int resID)
        {

        }
        
        public void OnCreate(int resID,Transform tf)
        {
            m_RefTrans = tf;
            // ResetTransform();
        }
        
        public void OnDestroy()
        {
            
        }

        public void SetPosition(Vector3 pos)
        {
            m_position = pos;
            if (m_RefTrans != null)
            {
                m_RefTrans.position = m_position;
            }
        }

        public void SetRotation(Vector3 rot)
        {
            m_rotation = rot;
            if (m_RefTrans != null)
            {
                m_RefTrans.localEulerAngles = m_rotation;
            }
        }

        public void SetScale(Vector3 scl)
        {
            m_scale = scl;
            if (m_RefTrans != null)
            {
                if (m_RefTrans.childCount > 0)
                {
                    for (int i = 0; i < m_RefTrans.childCount; i++)
                    {
                        m_RefTrans.GetChild(i).localScale = scl;
                    }
                }
                else
                {
                    m_RefTrans.localScale = scl;
                }
            }
        }

        public void SetOpenUp(int lodLv, float percent)
        {
            
        }

        private void ResetTransform()
        {
            m_RefTrans.position = m_position;
            m_RefTrans.localScale = m_scale;
            m_RefTrans.eulerAngles = m_rotation;
        }
    }
}